package com.example.controller;

import com.example.common.enums.ResponseCodeEnum;
import com.example.common.utils.ApiResult;
import com.example.model.query.PersonQuery;
import com.example.service.PersonService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * person Controller
 * 2020-08-27 18:59
 */
@Controller
@RestController
@RequestMapping("/person")
@CrossOrigin
@Api(value = "人员管理",tags={"物资人员接口"})
public class PersonController {

    @Autowired
    private PersonService personService;
    /*
     * 上传图片
     */
    @RequestMapping(value = "/imgUpload",method=RequestMethod.POST)
    @ResponseBody
    public Map<Boolean, String> imgUpload(HttpServletRequest request, HttpServletResponse response, MultipartFile file) throws IOException {
//        Map<String,Boolean> map = FileTypeUtil.getFileTypeISPic(file);
//        if(!map.get("success")){
//            Map mapMsg = new HashMap();
//            mapMsg.put(false,"上传图片格式只允许为jpg,png,gif,tif,bmp");
//            return mapMsg;
//        }
        return personService.imgUpload(request,response,file);
    }

    /**
     * 分页查询列表
     */
    @GetMapping("/page")
    public ApiResult<PersonQuery> pageByQuery(PersonQuery query) {
        try {
            return personService.pageUserVoByQuery(query);
        }   catch (Exception e) {
            e.printStackTrace();
            return new ApiResult<>(ResponseCodeEnum.MALL_SERVICE_PAGE_AD_FALSE);
        }
    }
}
